<template>
  <a-modal
    title="选择入库方式"
    width="300px"
    :visible="visible"
    dialogClass="zero-modal"
    @cancel="handleCancel"
  >
    <div class="shk-in-type-select-modal">
      <a-radio-group v-model="radioValue" :options="radioOptions" />
    </div>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button type="primary" key="ok" @click="onConfirm">确认</a-button>
    </template>
  </a-modal> 
</template>

<script>
export default {
  name:'shkInTypeSelectModal',
  emits:['update:visible','callback'],
  props:{
    visible:{
      type:Boolean,
      default:false
    }
  },
  data(){
    return {
      radioOptions:[],
      radioValue:'2'
    }
  },
  watch:{
    visible:{
      immediate:true,
      handler(newV,oldV){
        if (newV!==oldV){
          this.initShow()
          this.handleClose()
        }
      }
    }
  },
  created(){
    if (!this.radioOptions.length) {
      this.radioOptions = this.$options.filters['dictData']('task_model').map((item)=>{
        let obj = {}
        obj.value = item.code
        obj.label = item.name
        return obj
      })
    }
  },
  methods:{
    handleCancel(){
      this.$emit('update:visible',false)
    },
    initShow(){
      if (this.visible) {
        
      }
    },
    handleClose(){
      if (!this.visible) {
        this.radioValue = '2'
      }
    },
    onConfirm(){
      this.$emit('callback',this.radioValue)
      this.handleCancel()
    }
  }
}
</script>

<style lang="less" scoped>
.shk-in-type-select-modal{
  padding: 8px 16px;
}
</style>